package com.lizhangjun.nim.entity;

import lombok.Data;

/**
 * 系统统一响应实体
 * @author 11851
 */
@Data
public class Result
{
    /**
     * 是否成功
     */
    private boolean flag;
    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 返回信息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data;

    public Result() {
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result(boolean flag, Integer code, String message, Object data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 请求成功
     * @return result
     */
    public static Result ok(){
        return new Result(true, ResultCode.OK, "success");
    }

    /**
     * 请求成功
     * @param data 数据
     * @return result
     */
    public static Result ok(Object data){
        return new Result(true, ResultCode.OK, "success",data);
    }

    /**
     * 请求成功
     * @param message 返回信息
     * @param data 数据
     * @return result
     */
    public static Result ok(String message, Object data){
        return new Result(true, ResultCode.OK, message, data);
    }

    /**
     * 请求失败
     * @return result
     */
    public static Result fail(){
        return new Result(false, ResultCode.FAIL, "fail");
    }

    /**
     * 请求失败
     * @param message 返回信息
     * @return result
     */
    public static Result fail(String message){
        return new Result(false, ResultCode.FAIL, message);
    }

    /**
     * 请求失败
     * @param message 返回信息
     * @param data 返回数据
     * @return result
     */
    public static Result fail(String message, Object data){
        return new Result(false, ResultCode.FAIL, message, data);
    }

    /**
     * 资源不存在
     * @return result
     */
    public static Result notExist(){
        return new Result(false, ResultCode.NOT_EXIST, "资源不存在");
    }

    /**
     * 拒绝访问
     * @return result
     */
    public static Result denyAccess(){
        return new Result(false, ResultCode.DENY_ACCESS, "权限不足");
    }

    /**
     * 无访问权限
     * @return result
     */
    public static Result noAuth(){
        return new Result(false, ResultCode.NO_AUTH, "无访问权限");
    }

    /**
     * 系统错误
     * @return result
     */
    public static Result systemError(){
        return new Result(false, ResultCode.SYSTEM_ERROR, "系统错误");
    }

    /**
     * 系统繁忙
     * @return result
     */
    public static Result systemBusy(){
        return new Result(false, ResultCode.SYSTEM_BUSY, "系统繁忙");
    }

    /**
     * 认证失败
     * @return result
     */
    public static Result authenticationFail(){
        return new Result(false, ResultCode.AUTHENTICATION_FAIL, "认证失败");
    }

    /**
     * 登录过期
     * @return result
     */
    public static Result authenticationExpire(){
        return new Result(false, ResultCode.AUTHENTICATION_EXPIRE, "您的认证信息使用过期，为了您的账户安全，请重新登录，以获取新的认证信息！");
    }

    /**
     * 授权失败
     * @return result
     */
    public static Result authorizationFail(){
        return new Result(false, ResultCode.AUTHORIZATION_FAIL, "授权失败");
    }

    /**
     * sentinel限流异常
     * @return result
     */
    public static Result serviceLimit(){
        return new Result(false, ResultCode.SENTINEL_FLOW_LIMITING, "Sentinel限流拦截");
    }

    /**
     * 支付订单错误
     * @return result
     */
    public static Result orderFail(String message, Object data){
        return new Result(false, ResultCode.ORDER_FAIL, message, data);
    }

}


